﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using BullhornApiTest.BullhornApi;

namespace BullhornApiTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                BullhornApi.ApiServiceClient service = new BullhornApi.ApiServiceClient();
                BullhornApi.apiStartSessionResult result = service.startSession("dev1", "API123app", "EE3A19DF-FB2E-28F1-5F1EF99FF08317B2");
                String currentSession = result.session;

                dtoQuery myQuery = new dtoQuery();
                myQuery.entityName = "ClientContact";
                myQuery.maxResults = 50;

                // This query will find IDs of candidates with a status of 'New Lead" that were added after December 12, 2009
                // and are owned by CorporateUsers with an ID of 1, 2, 3, or 5.
                myQuery.where = "status = 'New Lead'";

                myQuery.orderBys = new String[] { "dateAdded desc", "id asc" };
                apiQueryResult qResult = service.query(currentSession, myQuery);

                object[] ids = qResult.ids;

                int clientContactId = Int32.Parse(ids[0].ToString());
                apiFindResult clientContactResult = service.find(currentSession, "ClientContact", clientContactId);
                currentSession = clientContactResult.session;
                clientContactDto thisClientContact = (clientContactDto)clientContactResult.dto;

                //dtoQuery myQuery = new dtoQuery();
                //myQuery.entityName = "DistributionList";
                //myQuery.maxResults = 50;

                //// This query will find IDs of candidates with a status of 'New Lead" that were added after December 12, 2009
                //// and are owned by CorporateUsers with an ID of 1, 2, 3, or 5.
                ////myQuery.where = "status = 'New Lead'";

                //myQuery.orderBys = new String[] { "dateAdded desc", "id asc" };
                //apiQueryResult qResult = service.query(currentSession, myQuery);

                //object[] ids = qResult.ids;

                //int dlId = Int32.Parse(ids[0].ToString());
                //apiFindResult dlResult = service.find(currentSession, "DistributionList", dlId);
                //currentSession = dlResult.session;
                //distributionListDto thisDl = (distributionListDto)dlResult.dto; 


                //EndpointAddress endpointAddress = new EndpointAddress("https://api.bullhornstaffing.com/webservices-2.5/");

                //BasicHttpBinding binding = new BasicHttpBinding();
                //binding.MessageEncoding = WSMessageEncoding.Mtom;
                //binding.Security.Mode = BasicHttpSecurityMode.Transport;
                //binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;

                //BullhornApi.ApiServiceClient service = new BullhornApi.ApiServiceClient(binding, endpointAddress);
                //BullhornApi.apiStartSessionResult result = service.startSession("dev1", "API123app", "EE3A19DF-FB2E-28F1-5F1EF99FF08317B2");
                //String session = result.session;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
